package com.ruoyi.web.controller.system;

import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.system.domain.SysUserConfig;
import com.ruoyi.system.service.SysUserConfigService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * @ClassName SysUserConfigController
 * @Description 描述
 * @Author HanWL
 * @Date 2024/6/2 23:54
 * @Version 1.0
 **/
@RestController
@RequestMapping("/sys/user/config")
public class SysUserConfigController {

    @Resource
    private SysUserConfigService configService;

    @GetMapping("/set/{root}/{money}")
    public String setMoney(@PathVariable("root")String root,@PathVariable("money") Long money) {
        if (!RuoYiConfig.getRoot().equals(root)){
            return "你个小逼崽子还想破解我？";
        }
        SysUserConfig config = new SysUserConfig();
        config.setMoney(money);
        boolean result = false;
        SysUserConfig one = configService.getById(1);
        if (Objects.isNull(one)){
            result = configService.save(config);
        } else {
            config.setId(1L);
            result = configService.updateById(config);
        }
        return result ? "success" : "false";
    }

    @GetMapping("/get/{root}")
    public Object getMoney(@PathVariable("root")String root) {
        if (!RuoYiConfig.getRoot().equals(root)){
            return "你个小逼崽子还想破解我？";
        }
        SysUserConfig one = configService.getById(1);
        return one.getMoney();
    }
}
